﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XCoder
{
    internal class XExtended_Property
    {
        public string TableName { get; set; }

        public string ColumnName { get; set; }

        public string Name { get; set; }

        public string Value { get; set; }

        public static XExtended_Property Parse(System.Data.DataRow row, System.Data.DatabaseType dbType)
        {
            XExtended_Property model = new XExtended_Property();
            switch (dbType)
            {
                case System.Data.DatabaseType.SqlServer:
                    #region SqlServer赋值
                    //  表名称
                    if (row.Table.Columns.Contains("TableName"))
                        model.TableName = row["TableName"] as string;
                    //  字段名称
                    if (row.Table.Columns.Contains("ColumnName"))
                        model.ColumnName = row["ColumnName"] as string;
                    //  属性名
                    if (row.Table.Columns.Contains("Name"))
                        model.Name = row["Name"] as string;
                    //  属性值
                    if (row.Table.Columns.Contains("Value"))
                        model.Value = row["Value"] as string;
                    #endregion
                    break;
                default:
                    break;
            }
            return model;
        }

        public static System.Collections.Generic.List<XExtended_Property> Parse(System.Data.DataTable source, System.Data.DatabaseType dbType)
        {
            System.Collections.Generic.List<XExtended_Property> models = new System.Collections.Generic.List<XExtended_Property>();
            if (source != null && source.Rows.Count > 0)
            {
                foreach (System.Data.DataRow row in source.Rows)
                {
                    var model = XExtended_Property.Parse(row, dbType);
                    models.Add(model);
                }
            }
            return models;
        }
    }
}
